<?php

namespace App\Events;

use App\Model\System\Organization;
use Illuminate\Queue\SerializesModels;

abstract class Event
{
    use SerializesModels;

    const CREATE = 1;
    const UPDATE = 2;
    const DELETE = 3;
    const STUDENT = 4;
    const CHECK = 5;
    const RESET = 6;
    const MESSAGE = 7;
    const NOTICE = 8;
    const LIVE = 9;
    const TASK = 10;


    public $action ;

    static protected $org = null;


    static function getOrg($field=null)
    {
        if(is_null(self::$org)){
            self::init();
        }
        if($field){
            return self::$org[$field];
        }
        return self::$org;
    }


    static protected function init()
    {
        if(is_null(self::$org)){
            $info = Organization::all();
            $info = $info[0];

            self::$org['SID'] = $info->SID;
            self::$org['timeStamp'] = time();
            self::$org['rootid'] = $info->rootid;
            self::$org['secret'] = $info->SafeKey;
            self::$org['safeKey'] = md5(self::$org['secret'].self::$org['timeStamp']);
            self::$org['eeourl'] = env('EEO_URL');
            self::$org['eeocloudurl'] = env('EEO_CLOUD_URL');
            self::$org['defaultCourseImage'] = $info->defaultCourseImage;
            self::$org['registerDefaultPwd'] = $info->registerDefaultPwd;
        }
    }


    function __construct()
    {
        self::init();
    }

}
